package com.itheima.produce;


import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/*
    发送消息
 */
public class Produce_Hello {

    public static void main(String[] args) throws IOException, TimeoutException {
        ConnectionFactory factory=new ConnectionFactory();
        factory.setHost("192.168.17.139");//默认为127.0.0.1
        factory.setPort(5672);
        factory.setVirtualHost("/itcast");//虚拟机
        factory.setUsername("zwy");//用户名
        factory.setPassword("123456");//密码
        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();
        //String queue, boolean durable, boolean exclusive, boolean autoDelete, Map<String, Object> arguments
        //队列名，是否持久化，是否独占，是否自动删除，参数
        channel.queueDeclare("hello",true,false,false,null);
        //String exchange, String routingKey, BasicProperties props, byte[] body
        //交换机  路由名称 配置信息 消息数据
        String body="hello ravvitMq  02";
        channel.basicPublish("","hello",null,body.getBytes());
        channel.close();
        connection.close();
    }

}
